package cn.yzfy.framework.starter.base.init;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @Author: 一朝风月
 * @Date: 2025/8/11 9:32
 * @Code 珍琅Code 研发
 * @Version: 1.0
 * @Description
 */
@RequiredArgsConstructor
public class ApplicationContentPostProcessor implements ApplicationListener<ApplicationReadyEvent> {
    private final ApplicationContext applicationContext;
    //原子性执行标识
    private final AtomicBoolean executeOnlyOnce = new AtomicBoolean(false);


    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        if (!executeOnlyOnce.compareAndSet(false, true)) {
            return;
        }
        applicationContext.publishEvent(new ApplicationInitializingEvent(this));
    }

    }

